﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplicationPlatform
{
    public partial class frmPageList : Form
    {
        private bool isLoad = true;

        public frmPageList()
        {
            InitializeComponent();

            initData();
        }

        /// <summary>
        /// 初始化数据测试分页
        /// </summary>
        private void initData()
        {
            UCPageInfo ucPage = this.ucPageSelect1.PageInfo;
            DataTable rdt = getSplitPageData(ucPage);
            this.dgvTestData.DataSource = rdt;
            

            if (this.isLoad)
            {
                this.ucPageSelect1.PageCount = 3;
                this.ucPageSelect1.RecordCount = 15;
            }

        }


        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        private DataTable getSplitPageData(UCPageInfo ucpage)
        {
            int pageSize = ucpage.PageSize;
            int currentPage = ucpage.CurryPage;

            DataTable rdt = new DataTable();
            rdt.Columns.Add("id");
            rdt.Columns.Add("name");

            for (int i = 0; i < pageSize; i++)
            {
                DataRow dr = rdt.NewRow();
                dr["id"] = i.ToString();
                dr["name"] = i + "[" + currentPage + "]";

                rdt.Rows.Add(dr);
            }

            return rdt;
        }

        private void ucPageSelect1_PageSelectIndexChangeItem(int page)
        {
            this.isLoad = false;
            initData();
        }
    }
}
